#!/bin/bash

# install base package
yum install -y bash-completion ntp ntpdate net-tools \
        tree wget make cmake gcc gcc-c++ createrepo \
        device-mapper-persistent-data lvm2 psmisc vim \
        lrzsz git vim-enhanced ntpdate ipvsadm conntrack-tools \
        socat conntrack ipvsadm ipset jq sysstat curl iptables libseccomp yum-utils


# change repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-Base.repo

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum clean all
yum -y makecache


# turn off the firewall
systemctl stop firewalld && systemctl disable firewalld

# set iptables rules
iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT


# disable SELINUX
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disable/' /etc/selinux/config


# close swap
swapoff -a && free –h
sed -i 's/.*swap.*/#&/g' /etc/fstab

# set system TimeZone
timedatectl set-timezone Asia/Shanghai

# written to the hardware clock
timedatectl set-local-rtc 0
systemctl  restart rsyslog && systemctl  restart crond

# ntpdate
ntpdate time.windows.com


# Load the kernel module

cat > /etc/sysconfig/modules/ipvs.modules <<EOF
modprobe  --  ip_vs
modprobe  --  nf_conntrack
modprobe  --  ip_vs_rr 
modprobe  --  ip_vs_wrr
modprobe  --  ip_vs_sh
modprobe  --  br_netfilter
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules  &&  bash   /etc/sysconfig/modules/ipvs.modules  &&  lsmod  |  grep -e ip_vs  -e  nf_conntrack


# add kubernetes.conf
cat > /etc/sysctl.d/kubernetes.conf <<-'EOF'
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness = 0
vm.overcommit_memory = 1
fs.file-max=52706963
fs.nr_open=52706963
EOF

sysctl -p /etc/sysctl.d/kubernetes.conf







